﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataProcessing
{
    public class Util
    {

        static public bool IsnotZero(double value)
        {
            return Math.Abs(value) > double.Epsilon;
        }
        static public int Truncate(int begin, int end,int value)
        {
            int ret = Math.Min(end, value);
            ret = Math.Max(ret, begin);
            return ret;
        }
        static public double ToSameScale(double fromStart,double fromEnd, double toStart,double toEnd,double value)
        {
            if (value < fromStart)
                return toStart;
            if (value > fromEnd)
                return toEnd;

            double ratio =  (value-fromStart) / (fromEnd - fromStart);
            return (toEnd - toStart) * ratio + toStart;
        }

        /// <summary>
        /// zongCount+1个marker
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <param name="zoneCount"></param>
        /// <returns></returns>
        static public int[] GenerateMarker(int begin, int end, int zoneCount)
        {
            int[] ret = new int[zoneCount + 1];
            double interval = ((double)(end - begin)) / zoneCount;
            for(int i=0;i<=zoneCount;i++)
            {
                ret[i] =(int)(begin + i * interval);
            }
            ret[zoneCount] = end;//为了精确度，手工给最后一个赋值

            return ret;

        }
    }
}
